package pc.system;

import java.util.*;
import pc.util.*;

public class Filter
{
  private Actions owner;
  private Hashtable filter = new Hashtable();

  public Filter(Actions owner)
  {
    this.owner = owner;
  }

  public void set(String name,String value)
  {
    if (value != null) filter.put(name, value);
  }

  public void set(String name,Object value)
  {
    if (value != null && value != null) set(name,value.toString());
  }

  public void set(String name)
  {
    String val = owner.getRequest().getValue(name);
    if (name != null && val != null) set(name,owner.getRequest().getValue(name));
  }

  private String getValue(String name,String def)
  {
    String val = (String)filter.get(name);
    if (val != null) return val;
    else return def;
  }

  public String getStringValue(String name)
  {
     return getValue(name,"");
  }

  public int getIntValue(String name)
  {
     String result = getValue(name,"0");
     if (result.equals("")) return 0;
     return Utils.strToInt(result);
  }

  public long getLongValue(String name)
  {
     String result = getValue(name,"0");
     if (result.equals("")) return 0;
     return Utils.strToLong(result);
  }

  public java.sql.Date getDateValue(String name)
  {
     String str = getValue(name,null);
     if (str == null) return Utils.nullDate;
     if (str.equals("")) return Utils.nullDate;
     if (str.equals(Utils.nullDate.toString())) return Utils.nullDate;
     return Utils.strToDate(str);
  }

  public java.sql.Date getDateText(String name)
  {
     String result = getValue(name,null);
     java.sql.Date date = Utils.strToDate(result);
     return (date != null) ? date : Utils.nullDate;
  }
}
